/**
 * 系统设置
 */
Ext.define('Module.System.SysConfig', {
	extend : 'Ext.panel.Panel',
	layout: 'border',
	initComponent : function() {
		var me = this;
		var store=Ext.create('Ext.data.Store',{
			autoLoad: true,
			fields: ['id','maxsession','maxconcurrent'],
	        proxy: {
	            type: 'ajax',
	            url: 'SysConfig/getConfigPage.do',
	            reader: {
					root: 'datas',
					totalProperty: 'total'
				}
	        }
		});
		
		var gridPanel = me.gridPanel = Ext.create('Ext.grid.Panel',{
			title: '系统配置',
			region: 'center',
			padding: '0 1 0 0',
//			width: 650,
			store: store,
			tbar:[{
				xtype: 'panel',
				border: false,
				height: 25,
				width: '100%',
				bodyPadding: 0-1,
				layout: 'column',
				defaults: {columnWidth: 1,bodyPadding: 0},
				items: [{
						xtype: 'toolbar',
						items: [{
							text: '修改配置',
							iconCls: 'icon-edit',
							handler: function(){
								me.updateXtsz();
							}
						}
					]
				 }]
			}],		
			bbar: Ext.create('Ext.PagingToolbar', {
	            store: store,
	            id: me.id+'-bbar',
	            displayInfo: true,
	            displayMsg: '显示第 {0} 至 {1} 条记录，共 {2} 条',
	            emptyMsg: "无记录"
	        }),
			columns: [{
	            text: '登录过期时间（分钟）',
	            flex: 2,
	            dataIndex: 'maxsession'
			},{
	            text: '最大访问用户数',
	            flex: 2,
	            dataIndex: 'maxconcurrent'
			}],
			listeners:{
				itemdblclick:function(s,rec,item){
					var uptime=Ext.Date.format(new Date(rec.data.uptime),'Y-m-d');
				}
			}
			
		});
		me.items = [gridPanel];
		me.callParent();
	},
	updateXtsz: function(){
		var me = this;
		Ext.create('Ext.window.Window',{
			width: 400,
			height: 150,
			iconCls: 'icon-edit',
			modal: true,
			layout: 'fit',
			title: '系统配置',
			buttons: [{
				text: '保存',
				handler: function(){
					var formp = this.up('panel').items.items[0];
        	    	var form = formp.getForm();
        	    	if(form.isValid()){
        	    		form.submit({
            	    	    url: 'SysConfig/editSysConfig.do?r='+Math.random(),
            	    	    success: function(form, action) {
            	    	    	var rs = Ext.decode(action.response.responseText);
            	    	    	if(rs.rst){
            	    	    		Ext.Msg.alert('提示', '保存成功！');
            	    	    		formp.up('window').close();
            	    	    		me.gridPanel.store.load();
            	    	    	}
            	    	    	else{
            	    	    		Ext.Msg.alert('提示', '修改失败！详情：<br>'+rs.msg);
            	    	    	}
            	    	    }
            	    	});
        	    	}
        	    	else{
        	    		Ext.Msg.alert('提示', '无效的配置,请正确填写！');
        	    	}
				}
			},{
				text: '取消',
				handler: function(){
					this.up('window').close();
				}
			}],
			items: me.getForm({
				bodyPadding: 10,
				border: false,
				listeners: {
					afterrender: function(formp){
						Ext.Ajax.request({
						    url: 'SysConfig/getConfig.do',
						    success: function(response){
						        var text = response.responseText;
						        var data = Ext.decode(text);
						        var values = {};
						        values.maxsession = data.maxsession;
						        values.maxconcurrent = data.maxconcurrent;
						        formp.form.setValues(values);
						    }
						});
					}
				}
				
			})
		}).show();
	},
	getForm: function(config){
		var me=this;
		return Ext.apply({
			xtype: 'form',
			bodyPadding: 10,
			fileUpload: true, 
			defaults: {anchor: '100%'},
			items: [{
					name: 'id',
					xtype: 'hidden'
					
				},new Ext.form.NumberField({  
	                fieldLabel:'登录过期时间（分钟）', 
	                name: 'maxsession',
	                maxValue:60,                       //最大值  
	                maxText:'值太大',  
	                minValue:1,                        //最小值  
	                minText:'值太小'  
	            }),new Ext.form.NumberField({  
	                fieldLabel:'最大访问用户数', 
	                name: 'maxconcurrent',
	                maxValue:5000,                       //最大值  
	                maxText:'值太大',  
	                minValue:100,                        //最小值  
	                minText:'值太小'  
	            })]
		},config);
	}
	
});



